<template>
  <star-horse-dialog :visible = "batchDialogTableVisible" :title = "dialogTitle" is-batch = "true" @merge = "merge"
                     @mergeDraft = "mergeDraft"
                     @reset = "resetForm">
    <el-table
        :data = "batchDataList"
        :row-class-name = "rowClassName"
        @selection-change = "handleDetailSelectionChange"
        border
        fit = "true"
        ref = "tb"
        v-loading = "loading"
    >
      <el-table-column fixed = "left" align = "center" type = "selection" width = "30"/>
      <el-table-column align = "center" label = "序号" prop = "xh" width = "50"></el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "区域主键"
          min-width = "200px"
          prop = "idAreainfo"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.idAreainfo'" required>
            <el-input-number clearable placeholder = "请输入区域主键"
                             v-model = "scope.row.idAreainfo"/>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "区域名称"
          min-width = "200px"
          prop = "areaName"
          sortable

          v-if = "true ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.areaName'" required>
            <el-input clearable placeholder = "请输入区域名称"
                      v-model = "scope.row.areaName"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "区域编码"
          min-width = "200px"
          prop = "areaCode"
          sortable

          v-if = "true ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.areaCode'" required>
            <el-input clearable placeholder = "请输入区域编码"
                      v-model = "scope.row.areaCode"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "父节点编号"
          min-width = "200px"
          prop = "parentNo"
          sortable

          v-if = "true ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.parentNo'" required>
            <el-input clearable placeholder = "请输入父节点编号"
                      v-model = "scope.row.parentNo"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改人"
          min-width = "200px"
          prop = "updatedBy"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.updatedBy'">
            <el-input clearable placeholder = "请输入修改人"
                      v-model = "scope.row.updatedBy"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改日期"
          min-width = "200px"
          prop = "updatedDate"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.updatedDate'">
            <el-date-picker clearable placeholder = "请选择修改日期"
                            type = "date"
                            v-model = "scope.row.updatedDate">
            </el-date-picker>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建人"
          min-width = "200px"
          prop = "createdBy"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.createdBy'">
            <el-input clearable placeholder = "请输入创建人"
                      v-model = "scope.row.createdBy"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建日期"
          min-width = "200px"
          prop = "createdDate"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.createdDate'">
            <el-date-picker clearable placeholder = "请选择创建日期"
                            type = "date"
                            v-model = "scope.row.createdDate">
            </el-date-picker>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "是否删除 1 是 0否"
          min-width = "200px"
          prop = "isDel"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.isDel'">
            <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                             v-model = "scope.row.isDel"/>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态名称"
          min-width = "200px"
          prop = "statusName"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.statusName'">
            <el-input clearable placeholder = "请输入状态名称"
                      v-model = "scope.row.statusName"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态编码"
          min-width = "200px"
          prop = "statusCode"
          sortable

          v-if = "true ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.statusCode'" required>
            <el-input clearable placeholder = "请输入状态编码"
                      v-model = "scope.row.statusCode"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统编号"
          min-width = "200px"
          prop = "dataNo"
          sortable

          v-if = " false ">
        <template #default = "scope">
          <el-form-item :prop = "'batchDataList.'+scope.$index+'.dataNo'">
            <el-input clearable placeholder = "请输入系统编号"
                      v-model = "scope.row.dataNo"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column fixed = "right" label = "操作" min-width = "150px">
        <template #header = "scope">
          <span>操作</span>&nbsp;&nbsp;
          <el-button @click = "handleAddDetails(scope.row,1)" link size = "mini" type = "primary">
            <el-tooltip content = "添加一行">
              <user-icon icon = "plus" style = "vertical-align: middle;color:#409EFF;"/>
            </el-tooltip>
          </el-button>
        </template>
        <template #default = "scope">
          <el-button v-if = "scope.row.xh==ruleForm.batchDataList.length" @click = "handleAddDetails(scope.row,1)" link
                     size = "mini" type = "primary">
            <el-tooltip content = "添加一行">添加</el-tooltip>
          </el-button>
          <el-button @click = "handleAddDetails(scope.row,2)" link size = "mini" type = "danger">
            <el-tooltip content = "删除当前行">删除</el-tooltip>
          </el-button>
        </template>
      </el-table-column>
    </el-table>

  </star-horse-dialog>

  <star-horse-dialog :visible = "dialogTableVisible" :title = "dialogTitle" @merge = "merge" @mergeDraft = "mergeDraft"
                     @reset = "resetForm">
    <el-form :model = "ruleForm" :rules = "rules" class = "demo-ruleForm" ref = "ruleForm">
      <el-form-item label = "区域主键" prop = "idAreainfo" v-if = "false">
        <el-input clearable placeholder = "请输入区域主键"
                  v-model = "ruleForm.idAreainfo"></el-input>
      </el-form-item>

      <el-form-item label = "区域名称" prop = "areaName"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入区域名称"
                  v-model = "ruleForm.areaName"></el-input>
      </el-form-item>

      <el-form-item label = "区域编码" prop = "areaCode"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入区域编码"
                  v-model = "ruleForm.areaCode"></el-input>
      </el-form-item>

      <el-form-item label = "父节点编号" prop = "parentNo"
                    v-if = "!false">
        <el-input clearable placeholder = "请输入父节点编号"
                  v-model = "ruleForm.parentNo"></el-input>
      </el-form-item>

      <el-form-item label = "修改人" prop = "updatedBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入修改人"
                  v-model = "ruleForm.updatedBy"></el-input>
      </el-form-item>

      <el-form-item label = "修改日期" prop = "updatedDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择修改日期" type = "date"
                        v-model = "ruleForm.updatedDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "创建人" prop = "createdBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入创建人"
                  v-model = "ruleForm.createdBy"></el-input>
      </el-form-item>

      <el-form-item label = "创建日期" prop = "createdDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择创建日期" type = "date"
                        v-model = "ruleForm.createdDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "是否删除 1 是 0否" prop = "isDel"
                    v-if = "!true">
        <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                         v-model = "ruleForm.isDel"/>
      </el-form-item>

      <el-form-item label = "状态名称" prop = "statusName"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入状态名称"
                  v-model = "ruleForm.statusName"></el-input>
      </el-form-item>

      <el-form-item label = "状态" prop = "statusCode"
                    v-if = "!false">
        <el-select placeholder = "请选择状态" v-model = "ruleForm.statusCode">
          <el-option
              :key = "sitem.statusCode"
              :label = "sitem.statusName"
              :value = "sitem.statusCode"
              clearable
              v-for = "sitem in selectData"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label = "系统编号" prop = "dataNo"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入系统编号"
                  v-model = "ruleForm.dataNo"></el-input>
      </el-form-item>
    </el-form>
  </star-horse-dialog>
  <star-horse-dialog :visible = "viewVisible" :title = "'查看数据'" :is-view = "true">
    <div class = "item">
      <label>父节点:</label>
      <div class = "content">{{ ruleForm.parentData ? ruleForm.parentData.areaName : "--" }}</div>
    </div>
    <div class = "item">
      <label>区域名称:</label>
      <div class = "content">{{ ruleForm.areaName }}</div>
    </div>
    <div class = "item">
      <label>区域编码:</label>
      <div class = "content">{{ ruleForm.areaCode }}</div>
    </div>
    <div class = "item">
      <label>状态名称:</label>
      <div class = "content">{{ ruleForm.statusName }}</div>
    </div>
    <div class = "item">
      <label>创建人:</label>
      <div class = "content">{{ ruleForm.createdBy }}</div>
    </div>
    <div class = "item">
      <label>创建日期:</label>
      <div class = "content">{{ createDate(ruleForm.createdDate) }}</div>
    </div>
  </star-horse-dialog>
  <el-card class = "inner_content">
    <!--查询区域-->
    <el-form class = "search_area" size = "default">
      <el-form-item label = "区域名称">
        <el-input placeholder = "请输入区域名称" v-model = "searchForm.areaName"/>
      </el-form-item>
      <el-form-item label = "区域编码">
        <el-input placeholder = "请输入区域编码" v-model = "searchForm.areaCode"/>
      </el-form-item>
      <el-form-item label = "添加时间">
        <el-date-picker
            end-placeholder = "结束日期" placeholder = "请选择添加时间"
            range-separator = "到"
            start-placeholder = "开始日期"
            type = "daterange"
            v-model = "searchForm.createdDate"
        />
      </el-form-item>
      <el-form-item label = "     ">
        <el-button @click = "dataSearch" link type = "primary">
          <user-icon icon = "search"/>
          <span style = "vertical-align: middle;"> 查询 </span>
        </el-button>
        <el-button @click = "dataSearch(1)" link small>
          <span style = "vertical-align: middle;"> 重置 </span>
        </el-button>
      </el-form-item>
    </el-form>
    <el-divider/>
    <star-horse-button-list
        :permission = "permission"
        :upload-url = "uploadUrl"
        @upload = "upload"
        @uploadProcess = "uploadProcess"
        @uploadError = "uploadError"
        @uploadSuccess = "uploadProcess"
        @btnOperation = "btnOperation"
    />
    <el-table
        :data = "dataList"
        :row-key = "getRowIdentity"
        @row-dblclick = "editData"
        @selection-change = "handleSelectionChange"
        border
        fit = "true"
        highlight-current-row = "true"
        id = "areainfoPo"
        ref = "multipleTable"
        stripe = "true"
    >
      <el-table-column fixed width = "1"/>
      <el-table-column
          :reserve-selection = "true"
          align = "center"
          fixed = "left"
          type = "selection"
      />
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "区域主键"
          min-width = "200px"
          prop = "idAreainfo"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "区域名称"
          min-width = "200px"
          prop = "areaName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "区域编码"
          min-width = "200px"
          prop = "areaCode"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "父节点"
          min-width = "200px"
          prop = "parentData.areaName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改人"
          min-width = "200px"
          prop = "updatedBy"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改日期"
          min-width = "200px"
          prop = "updatedDate"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建人"
          min-width = "200px"
          prop = "createdBy"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建日期"
          min-width = "200px"
          prop = "createdDate"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "是否删除 1 是 0否"
          min-width = "200px"
          prop = "isDel"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态名称"
          min-width = "200px"
          prop = "statusName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态编码"
          min-width = "200px"
          prop = "statusCode"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统编号"
          min-width = "200px"
          prop = "dataNo"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column fixed = "right" label = "操作" min-width = "180px">
        <template #default = "scope">
          <el-button v-if = "permission.edit" @click = "editById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "编辑">编辑</el-tooltip>
          </el-button>
          <el-button v-if = "permission.view" @click = "viewById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "查看">查看</el-tooltip>
          </el-button>
          <el-button v-if = "permission.delete" @click = "deleteById(scope.row[primaryKey])" link title = ""
                     type = "danger">
            <el-tooltip content = "删除">删除</el-tooltip>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-divider/>
    <el-pagination
        :total = "totalData"
        @current-change = "pageChangeClick"
        @size-change = "pageSizeClick"
        layout = "total, sizes, prev, pager, next, jumper"
        v-model:currentPage = "currentPage"
        v-model:page-size = "pageSize"
        v-model:pageCount = "totalPage"/>
  </el-card>
</template>
<style>

</style>
<script>

import {ref} from "vue";
import {common} from "../../api/common";

export default {
  name: "AreainfoEntity",

  mixins: [common],
  setup() {
    return {}
  },
  data() {
    const loadByPageUrl = ref("/system-config/system/areainfoEntity/pageList");
    const mergeUrl = ref("/system-config/system/areainfoEntity/merge");
    const mergeDraftUrl = ref("/system-config/system/areainfoEntity/mergeDraft");
    const batchMergeUrl = ref("/system-config/system/areainfoEntity/mergeBatch");
    const batchMergeDraftUrl = ref("/system-config/system/areainfoEntity/mergeBatchDraft");
    const loadByIdUrl = ref("/system-config/system/areainfoEntity/getById");
    const uploadUrl = "/system-config/system/areainfoEntity/importData";
    const deleteUrl = ref("/system-config/system/areainfoEntity/batchDeleteById");
    const exportAllUrl = ref("/system-config/system/areainfoEntity/exportData");
    const downloadTemplateUrl = ref("/system-config/system/areainfoEntity/downloadTemplate");
    const primaryKey = "idAreainfo";
    return {
      loadByPageUrl,
      mergeUrl,
      uploadUrl,
      mergeDraftUrl,
      batchMergeUrl,
      batchMergeDraftUrl,
      loadByIdUrl,
      deleteUrl,
      exportAllUrl,
      downloadTemplateUrl,
      primaryKey,
      rules: {
        areaName: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        areaCode: [{required: true, message: "必选项不能为空", trigger: "blur"}],
      }
    }
  },
  methods: {
    dataFormat(row, column, cellValue, index) {
      cellValue = this.commonDataFormat(row, column, cellValue, index);
      return cellValue;
    },
    parseSearchData: function () {
      let data = this.searchForm;
      let arr = [];
      if (data.areaName) {
        arr.push({
          propertyName: "areaName",
          value: data.areaName,
          operation: "lk"
        });
      }
      if (data.areaCode) {
        arr.push({
          propertyName: "areaCode",
          value: data.areaCode,
          operation: "lk"
        });
      }

      if (data.createdDate) {
        arr.push({
          propertyName: "createdDate",
          value: data.createdDate,
          operation: "bt"
        });
      }
      return arr;
    },
    /**
     * 初始化数据
     */
    init: function () {
      this.dataList = [];
      this.selectData = [];
      this.loadByPage(this.currentPage, this.pageSize);
      this.loadPermissionResources();
      this.commonSelectData("sys_areainfo");

    }
  },
  created() {
    this.init();
  }
}
</script>